package com.visikard.response;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;

import android.util.Log;

import com.visikard.application.Constant;
import com.visikard.item.CouponBuilderItem;

public class GetListCouponResponse extends BaseResponse {
	public static final int ERROR_NOT_FOUND = BaseResponse.USER_DEFINED_ERROR;

	private ArrayList<CouponBuilderItem> list;

	public void setList(ArrayList<CouponBuilderItem> list) {
		this.list = list;
	}

	public ArrayList<CouponBuilderItem> getList() {
		return list;
	}

	@Override
	public void extractDataFromServer(String response) throws JSONException {
		super.extractDataFromServer(response);
		Log.e("GetListCouponResponse>", response);
		if (errorCode == SUCCESS) {

			JSONArray jsArr = getDataJArray(response);
			ArrayList<CouponBuilderItem> coupons = new ArrayList<CouponBuilderItem>();
			for (int i = 0; i < jsArr.length(); i++) {
				CouponBuilderItem item = new CouponBuilderItem(jsArr.getJSONObject(i));
				coupons.add(item);
			}
			list = coupons;

		}
		else if (response != null && !response.isEmpty() && response.equals("Not Found")) {
			Log.e(Constant.LOG_TAG, "getListCoupon: " + "Not Found!!!");
			errorCode = GetListCouponResponse.ERROR_NOT_FOUND;
			errorMsg = "Not Found";
		}
	}

}
